package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCommentMapper;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author YDW
 * projectName:shop-manage
 * time:2022/5/23 15:58
 * description:
 */
@Service
public class DtsCommentServiceImpl implements DtsCommentService {

    @Autowired
    DtsCommentMapper commentMapper;

    @Override
    public IPage<DtsComment> queryPage(Integer page, Integer limit, String sort, String order, Integer userId, Integer goodsId, List<Integer> brandIds) {

        IPage<DtsComment> ipage= new Page<>(page,limit);
        QueryWrapper<DtsComment> qw=new QueryWrapper<>();
        qw.eq("c.deleted",false);
        if(goodsId!=null){
            qw.like("c.value_id",goodsId);
        }
        if (userId!=null){
            qw.like("c.user_id",userId);
        }
        if(brandIds!=null&&brandIds.size()>0){
            qw.in("p.brand_id",brandIds);
        }

        commentMapper.selectCommentPage(ipage,qw);


        return ipage;
    }

    @Override
    public void delete(DtsComment comment) {
        comment.setDeleted(true);
        commentMapper.updateById(comment);
    }
}
